<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  <head>
    <title>Logical Number Operations</title>
    <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
    <link rel="stylesheet" type="text/css" href="kawa.css"/>
    <script src="kawa-ebook.js" type="text/javascript"/>
    <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
    <link rel="prev" href="Overall-Index.xhtml" title="Index"/>
    <link rel="next" href="Performance-of-numeric-operations.xhtml" title="Performance of numeric operations"/>
  </head>
  <body>
    <header/>
    <section class="sect1" title="Logical Number Operations" epub:type="subchapter" id="Logical-Number-Operations">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both">Logical Number Operations</h2>
          </div>
        </div>
      </div>
      <p>These functions operate on the 2’s complement binary representation
of an exact integer.
</p>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876191456" class="indexterm"/> <code class="function">bitwise-not</code> <em class="replaceable"><code>i</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the bit-wise logical inverse of the argument.
More formally, returns the exact integer whose two’s
complement representation is the one’s complement of the two’s
complement representation of <em class="replaceable"><code>i</code></em>.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876187536" class="indexterm"/>  <code class="function">bitwise-and</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>...</code></em></p>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876184352" class="indexterm"/> <code class="function">bitwise-ior</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>...</code></em></p>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876181168" class="indexterm"/> <code class="function">bitwise-xor</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>...</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>These procedures return the exact integer that is the bit-wise
“and”, “inclusive or”, or “exclusive or” of the two’s
complement representations of their arguments.
If they are passed only one argument, they return that argument.
If they are passed no arguments, they return the integer
that acts as identity for the operation: -1, 0, or 0, respectively. 
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876176704" class="indexterm"/> <code class="function">bitwise-if</code> <em class="replaceable"><code>i1</code></em> <em class="replaceable"><code>i2</code></em> <em class="replaceable"><code>i3</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the exact integer that is the bit-wise “if” of the twos
complement representations of its arguments, i.e. for each bit, if it
is 1 in i1, the corresponding bit in i2 becomes the value of the
corresponding bit in the result, and if it is 0, the corresponding bit
in i3 becomes the corresponding bit in the value of the result. This
is equivaent to the following computation:
</p>
          <pre class="screen">(bitwise-ior (bitwise-and i1 i2)
             (bitwise-and (bitwise-not i1) i3))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876171216" class="indexterm"/> <code class="function">bitwise-bit-count</code> <em class="replaceable"><code>i</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>If i is non-negative, returns the number of 1 bits in the twos complement
representation of i. Otherwise it returns the result of the following
computation:
</p>
          <pre class="screen">(bitwise-not (bitwise-bit-count (bitwise-not i)))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876167408" class="indexterm"/> <code class="function">bitwise-length</code> <em class="replaceable"><code>i</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the number of bits needed to represent i if it is positive,
and the number of bits needed to represent <code class="literal">(bitwise-not <em class="replaceable"><code>i</code></em>)</code>
if it is negative, which is the exact integer that is the result of the
following computation:
</p>
          <pre class="screen">(do ((result 0 (+ result 1))
     (bits (if (negative? i)
               (bitwise-not i)
               ei)
           (bitwise-arithmetic-shift bits -1)))
    ((zero? bits)
     result))
</pre>
          <p>This is the number of bits needed to represent <em class="replaceable"><code>i</code></em> in an unsigned field.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876161856" class="indexterm"/> <code class="function">bitwise-first-bit-set</code> <em class="replaceable"><code>i</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the index of the least significant 1 bit in the twos complement
representation of i. If i is 0, then - 1 is returned.
</p>
          <pre class="screen">(bitwise-first-bit-set 0) ⇒ -1
(bitwise-first-bit-set 1) ⇒ 0
(bitwise-first-bit-set -4) ⇒ 2
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876158000" class="indexterm"/> <code class="function">bitwise-bit-set?</code> <em class="replaceable"><code>i1</code></em> <em class="replaceable"><code>i2</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns <code class="literal">#t</code> if the i2’th bit (where <em class="replaceable"><code>i2</code></em> must be non-negative)
is 1 in the two’s complement representation of <em class="replaceable"><code>i1</code></em>, and <code class="literal">#f</code>
otherwise. This is the result of the following computation:
</p>
          <pre class="screen">(not (zero?
       (bitwise-and
         (bitwise-arithmetic-shift-left 1 i2)
         i1)))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876152112" class="indexterm"/> <code class="function">bitwise-copy-bit</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>bitno</code></em> <em class="replaceable"><code>replacement-bit</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the result of replacing the <em class="replaceable"><code>bitno</code></em>’th bit of <em class="replaceable"><code>i</code></em>
by <em class="replaceable"><code>replacement-bit</code></em>, where <em class="replaceable"><code>bitno</code></em> must be non-negative,
and <em class="replaceable"><code>replacement-bit</code></em> must be either 0 or 1.
This is the result of the following computation:
</p>
          <pre class="screen">(let* ((mask (bitwise-arithmetic-shift-left 1 bitno)))
  (bitwise-if mask
            (bitwise-arithmetic-shift-left replacement-bit bitno)
            i))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876145184" class="indexterm"/> <code class="function">bitwise-bit-field</code> <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the integer formed from the (unsigned) bit-field
starting at <em class="replaceable"><code>start</code></em> and ending just before <em class="replaceable"><code>end</code></em>.
Same as:
</p>
          <pre class="screen">(let ((mask
       (bitwise-not
        (bitwise-arithmetic-shift-left -1 <em class="replaceable"><code>end</code></em>))))
  (bitwise-arithmetic-shift-right
    (bitwise-and <em class="replaceable"><code>n</code></em> mask)
    <em class="replaceable"><code>start</code></em>))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876138464" class="indexterm"/> <code class="function">bitwise-copy-bit-field</code> <em class="replaceable"><code>to</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em> <em class="replaceable"><code>from</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the result of replacing in <em class="replaceable"><code>to</code></em> the bits at positions from <em class="replaceable"><code>start</code></em> (inclusive) to <em class="replaceable"><code>end</code></em> (exclusive) by the bits in <em class="replaceable"><code>from</code></em> from position 0 (inclusive) to position <em class="replaceable"><code>end</code></em> - <em class="replaceable"><code>start</code></em> (exclusive).
Both <em class="replaceable"><code>start</code></em> and <em class="replaceable"><code>start</code></em> must be non-negative,
and <em class="replaceable"><code>start</code></em> must be less than or equal to <em class="replaceable"><code>start</code></em>.
</p>
          <p>This is the result of the following computation:
</p>
          <pre class="screen">(let* ((mask1
         (bitwise-arithmetic-shift-left -1 start))
       (mask2
         (bitwise-not
           (bitwise-arithmetic-shift-left -1 end)))
       (mask (bitwise-and mask1 mask2)))
  (bitwise-if mask
              (bitwise-arithmetic-shift-left from
                                             start)
              to))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876128320" class="indexterm"/> <code class="function">bitwise-arithmetic-shift</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Shifts <em class="replaceable"><code>i</code></em> by <em class="replaceable"><code>j</code></em>.
It is a “left” shift if <code class="literal"><em class="replaceable"><code>j</code></em>&gt;0</code>, and
a “right” shift if <code class="literal"><em class="replaceable"><code>j</code></em>&lt;0</code>.
The result is equal to <code class="literal">(floor (* <em class="replaceable"><code>i</code></em> (expt 2 <em class="replaceable"><code>j</code></em>)))</code>.
</p>
          <p>Examples:
</p>
          <pre class="screen">(bitwise-arithmetic-shift -6 -1) ⇒-3
(bitwise-arithmetic-shift -5 -1) ⇒ -3
(bitwise-arithmetic-shift -4 -1) ⇒ -2
(bitwise-arithmetic-shift -3 -1) ⇒ -2
(bitwise-arithmetic-shift -2 -1) ⇒ -1
(bitwise-arithmetic-shift -1 -1) ⇒ -1
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876119968" class="indexterm"/> <code class="function">bitwise-arithmetic-shift-left</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>amount</code></em></p>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876116720" class="indexterm"/> <code class="function">bitwise-arithmetic-shift-right</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>amount</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>The <em class="replaceable"><code>amount</code></em> must be non-negative
The <code class="literal">bitwise-arithmetic-shift-left</code> procedure returns the same
result as <code class="literal">bitwise-arithmetic-shift</code>,
and <code class="literal">(bitwise-arithmetic-shift-right <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>amount</code></em>)</code> returns the
same result as <code class="literal">(bitwise-arithmetic-shift <em class="replaceable"><code>i</code></em> (- <em class="replaceable"><code>amount</code></em>))</code>.
</p>
          <p>If <em class="replaceable"><code>i</code></em> is a primitive integer type,
then <em class="replaceable"><code>amount</code></em> must be less than the number of bits in the
promoted type of <em class="replaceable"><code>i</code></em> (32 or 64).
If the type is unsigned, an unsigned (logic) shift is
done for <code class="literal">bitwise-arithmetic-shift-right</code>,
rather than a signed (arithmetic) shift.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876106688" class="indexterm"/> <code class="function">bitwise-rotate-bit-field</code> <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em> <em class="replaceable"><code>count</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the result of cyclically permuting in <em class="replaceable"><code>n</code></em> the bits at positions
from <em class="replaceable"><code>start</code></em> (inclusive) to <em class="replaceable"><code>end</code></em> (exclusive) by
<em class="replaceable"><code>count</code></em> bits towards the more significant bits,
<em class="replaceable"><code>start</code></em> and <em class="replaceable"><code>end</code></em> must be non-negative,
and <em class="replaceable"><code>start</code></em> must be less than or equal to <em class="replaceable"><code>end</code></em>.
This is the result of the following computation:
</p>
          <pre class="screen">(let* ((n     ei1)
       (width (- end start)))
  (if (positive? width)
      (let* ((count (mod count width))
             (field0
               (bitwise-bit-field n start end))
             (field1 (bitwise-arithmetic-shift-left
                       field0 count))
             (field2 (bitwise-arithmetic-shift-right
                       field0
                       (- width count)))
             (field (bitwise-ior field1 field2)))
        (bitwise-copy-bit-field n start end field))
      n))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876097712" class="indexterm"/> <code class="function">bitwise-reverse-bit-field</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the result obtained from <em class="replaceable"><code>i</code></em> by reversing the order of the bits at positions from <em class="replaceable"><code>start</code></em> (inclusive) to <em class="replaceable"><code>end</code></em> (exclusive),
where <em class="replaceable"><code>start</code></em> and <em class="replaceable"><code>end</code></em> must be non-negative,
and <em class="replaceable"><code>start</code></em> must be less than or equal to <em class="replaceable"><code>end</code></em>.
</p>
          <pre class="screen">(bitwise-reverse-bit-field #b1010010 1 4) ⇒  88 ; #b1011000
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876090112" class="indexterm"/> <code class="function">logop</code> <em class="replaceable"><code>op</code></em> <em class="replaceable"><code>x</code></em> <em class="replaceable"><code>y</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Perform one of the 16 bitwise operations of <em class="replaceable"><code>x</code></em> and <em class="replaceable"><code>y</code></em>,
depending on <em class="replaceable"><code>op</code></em>.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876084704" class="indexterm"/> <code class="function">logtest</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns true if the arguments have any bits in common.
Same as <code class="literal">(not (zero? (bitwise-and <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em>)))</code>,
but is more efficient.
</p>
        </blockquote>
      </div>
      <section class="sect2" title="SRFI-60 Logical Number Operations" epub:type="division" id="idm139667876079808">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title">SRFI-60 Logical Number Operations</h3>
            </div>
          </div>
        </div>
        <p>Kawa supports SRFI-60 “Integers as Bits” as well, although we
generally recommend using the R6RS-compatible functions instead when
possible.  Unless noted as being a builtin function, to use these you
must first <code class="literal">(require 'srfi-60)</code> or <code class="literal">(import (srfi :60))</code>
(or <code class="literal">(import (srfi :60 integer-bits))</code>).
</p>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876076544" class="indexterm"/> <code class="function">logand</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>...</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-and <em class="replaceable"><code>i</code></em> ...)</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876071952" class="indexterm"/> <code class="function">logior</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>...</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-ior <em class="replaceable"><code>i</code></em> ...)</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876067360" class="indexterm"/> <code class="function">logxor</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>...</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-xor <em class="replaceable"><code>i</code></em> ...)</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876062768" class="indexterm"/> <code class="function">lognot</code> <em class="replaceable"><code>i</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-not <em class="replaceable"><code>i</code></em>)</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876058592" class="indexterm"/> <code class="function">bitwise-merge</code> <em class="replaceable"><code>mask</code></em> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-if <em class="replaceable"><code>mask</code></em> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876052848" class="indexterm"/> <code class="function">any-bits-set?</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(logtest <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876047936" class="indexterm"/> <code class="function">logcount</code> <em class="replaceable"><code>i</code></em></p>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876045136" class="indexterm"/> <code class="function">bit-count</code> <em class="replaceable"><code>i</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Count the number of 1-bits in <em class="replaceable"><code>i</code></em>, if it is non-negative.
If <em class="replaceable"><code>i</code></em> is negative, count number of 0-bits.
Same as <code class="literal">(bitwise-bit-count <em class="replaceable"><code>i</code></em>)</code> if <em class="replaceable"><code>i</code></em> is non-negative.
Builtin as <code class="literal">logcount</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876039216" class="indexterm"/> <code class="function">integer-length</code> <em class="replaceable"><code>i</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-length <em class="replaceable"><code>i</code></em>)</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876035040" class="indexterm"/> <code class="function">log2-binary-factors</code> <em class="replaceable"><code>i</code></em></p>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876032240" class="indexterm"/> <code class="function">first-set-bit</code> <em class="replaceable"><code>i</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-first-bit-set <em class="replaceable"><code>i</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876028096" class="indexterm"/> <code class="function">logbit?</code> <em class="replaceable"><code>pos</code></em> <em class="replaceable"><code>i</code></em></p>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876024912" class="indexterm"/> <code class="function">bit-set?</code> <em class="replaceable"><code>pos</code></em> <em class="replaceable"><code>i</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-bit-set? <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>pos</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876020000" class="indexterm"/> <code class="function">copy-bit</code> <em class="replaceable"><code>bitno</code></em> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>bool</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-copy-bit <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>bitno</code></em> (if <em class="replaceable"><code>bool</code></em> 1 0))</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876014128" class="indexterm"/> <code class="function">bit-field</code> <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-bit-field <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876008384" class="indexterm"/> <code class="function">copy-bit-field</code> <em class="replaceable"><code>to</code></em> <em class="replaceable"><code>from</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-copy-bit-field <em class="replaceable"><code>to</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em> <em class="replaceable"><code>from</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876001792" class="indexterm"/> <code class="function">arithmetic-shift</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-arithmetic-shift <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em>)</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875996832" class="indexterm"/> <code class="function">ash</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>j</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Alias for <code class="literal">arithmetic-shift</code>.  Builtin.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875992720" class="indexterm"/> <code class="function">rotate-bit-field</code> <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>count</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-rotate-bit-field <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em> <em class="replaceable"><code>count</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875986128" class="indexterm"/> <code class="function">reverse-bit-field</code> <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-reverse-bit-field <em class="replaceable"><code>i</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em>)</code>.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875980368" class="indexterm"/> <code class="function">integer-&gt;list</code> <em class="replaceable"><code><em class="replaceable"><code>k</code></em></code></em> [<em class="replaceable"><code><em class="replaceable"><code>length</code></em></code></em>]</p>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875976768" class="indexterm"/> <code class="function">list-&gt;integer</code> <em class="replaceable"><code><em class="replaceable"><code>list</code></em></code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>The <code class="literal">integer-&gt;list</code> procedure returns a list of <em class="replaceable"><code>length</code></em>
booleans corresponding to the bits of the non-negative integer <em class="replaceable"><code>k</code></em>,
with <code class="literal">#t</code> for <code class="literal">1</code> and <code class="literal">#f</code> for <code class="literal">0</code>.  <em class="replaceable"><code>length</code></em>
defaults to <code class="literal">(bitwise-length <em class="replaceable"><code>k</code></em>)</code>.  The list will be in order
from MSB to LSB, with the value of <code class="literal">(odd? <em class="replaceable"><code>k</code></em>)</code> in the last
car.
</p>
            <p>The <code class="literal">list-&gt;integer</code> procedure returns the integer corresponding to
the booleans in the list <em class="replaceable"><code>list</code></em>.
The <code class="literal">integer-&gt;list</code> and <code class="literal">list-&gt;integer</code> procedures are
inverses so far as <code class="literal">equal?</code> is concerned.
</p>
          </blockquote>
        </div>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875965360" class="indexterm"/> <code class="function">booleans-&gt;integer</code> <em class="replaceable"><code>bool1</code></em> <em class="replaceable"><code>...</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Returns the integer coded by the <em class="replaceable"><code>bool1</code></em> ... arguments.
Equivalent to <code class="literal">(list-&gt;integer (list <em class="replaceable"><code>bool1</code></em> ...))</code>.
</p>
          </blockquote>
        </div>
      </section>
      <section class="sect2" title="Deprecated Logical Number Operations" epub:type="division" id="idm139667875960208">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title">Deprecated Logical Number Operations</h3>
            </div>
          </div>
        </div>
        <p>This older function is still available, but we
recommend using the R6RS-compatible function.
</p>
        <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667875958624" class="indexterm"/> <code class="function">bit-extract</code> <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em></p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <p>Equivalent to <code class="literal">(bitwise-bit-field <em class="replaceable"><code>n</code></em> <em class="replaceable"><code>start</code></em> <em class="replaceable"><code>end</code></em>)</code>.
</p>
          </blockquote>
        </div>
      </section>
    </section>
    <footer>
      <div class="navfooter">
        <ul>
          <li>
            <b class="toc">
              <a href="Logical-Number-Operations.xhtml#idm139667876079808">SRFI-60 Logical Number Operations</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Logical-Number-Operations.xhtml#idm139667875960208">Deprecated Logical Number Operations</a>
            </b>
          </li>
        </ul>
        <p>
          Up: <a accesskey="u" href="Numbers.xhtml">Quantities and Numbers</a></p>
        <p>
        Previous: <a accesskey="p" href="Quantities.xhtml">Quantities and Units</a></p>
        <p>
        Next: <a accesskey="n" href="Performance-of-numeric-operations.xhtml">Performance of numeric operations</a></p>
      </div>
    </footer>
  </body>
</html>
